/*package Utils;

public class Frame {
	private ArrayList<IDonnee> tab;
	private int nbOctet;
	private int nbDonnee;
	private byte priorite;

	public Frame(){		
		this.tab = new ArrayList<IDonnee>();
		this.nbOctet = 3;
		this.nbDonnee = 0;
		this.priorite = (byte)0x00;
	}

	public void setPriorite(byte n){
		this.priorite = n;
	}

	public int getPriorite(){
		return this.priorite;
	}

	// Remise a zero d'une trame (facilite l'utilisation)
	// Plus besoin de creer n Trame il suffit de reset.
	public void reset(){
		tab.clear();
		this.nbOctet = 3;
		this.nbDonnee = 0;
		this.priorite = (byte)0x00;
	}

	public ArrayList<IDonnee> getDonnees(){
		return this.tab;
	}

	public void add(IDonnee donnee){
		tab.add(donnee);
		this.nbDonnee++;
		this.nbOctet += donnee.getTab().length;
	}

	// Conversion de trame en String
	public String toString(){
		StringBuffer sb = new StringBuffer();
		sb.append("{ ");
		sb.append("0x"+Integer.toString( ( this.priorite & 0xff ) + 0x100, 16).substring( 1 ).toUpperCase());
		for(IDonnee donnee : tab){
			sb.append(", ");
			sb.append(donnee.toString());
		}
		sb.append(" }");
		return sb.toString();
	}

	// Recupere une trame sur le flux en mode bloquant
	public boolean decode(InputStream in){
		if (lireByte(in) == (byte) 0xFF){
			this.priorite = lireByte(in);
			if(priorite == -1)
				return false;
			this.nbDonnee = lireByte(in)&0xFF;
			lire(nbDonnee, in);
		}
		return true;
	}

	// Lecture d'un octet sur le flux
	private byte lireByte(InputStream in){
		try {
			return (byte) in.read();
		} catch (IOException e) {
			e.printStackTrace();
			return -1;
		}
	}

	// Analyse de la trame 
	private void lire(int nbDonnee, InputStream in){
		int i=0;
		byte b;
		try{
			while(i<nbDonnee){
				b = lireByte(in);
				switch(b){
				case (byte) 0x01:
					b = lireByte(in);
				tab.add(new SignedByte(b));
				this.nbOctet += 2;
				break;
				case (byte) 0x02:
					tab.add(new SignedShort(lireByte(in)<<8 | lireByte(in)&0xFF));
				this.nbOctet += 3;
				break;
				case (byte) 0x04:
					tab.add(new SignedInt( lireByte(in)<<24 | (lireByte(in)&0xFF)<<16 | (lireByte(in)&0xFF)<<8 | lireByte(in)&0xFF ));
				this.nbOctet += 5;
				break;
				case (byte) 0x11:
					tab.add(new UnsignedByte(lireByte(in)&0xFF));
				this.nbOctet += 2;
				break;
				case (byte) 0x12:
					tab.add(new UnsignedShort((lireByte(in)&0xFF)<<8 | lireByte(in)&0xFF));
				this.nbOctet += 3;
				break;
				case (byte) 0x14:
					tab.add(new UnsignedInt((lireByte(in)&0xFF)<<24 | (lireByte(in)&0xFF)<<16 | (lireByte(in)&0xFF)<<8 | lireByte(in)&0xFF));
				this.nbOctet += 5;
				break;
				case (byte) 0x20:
					//taille
					int taille = (int)lireByte(in)&0xFF<<8 | lireByte(in)&0xFF;
				//string
				byte[] bytes = new byte[taille];
				in.read(bytes);
				tab.add(new DString( new String( bytes ,"UTF8") ));
				this.nbOctet += taille+3;
				break;
				case (byte) 0x30:// float
					break;
				}
				i++;
			}
		}
		catch(Exception e){
			System.out.println("probleme dans lire");
			e.printStackTrace();
		}
	}


	// Ajout d'une String 
	public boolean add(String s) throws Exception{
		byte[] tab = s.getBytes();
		byte length = (byte) tab.length;
		byte[] b = new byte[length+3];
		b[0] = (byte) 0x20;
		b[1] = (byte) length;


		for(int i=0; i<tab.length; i++){
			b[i+2] = tab[i];
		}

		this.nbOctet+=b.length;
		this.nbDonnee++;		
		this.tab.add(new DString(s));
		return true;
	}

	// Ajout d'un float aux donnees
	public boolean add(double d) throws Exception{
		byte[] b = new byte[9];
		b[0] = (byte) 0x30;

		DecimalFormat df = new DecimalFormat ( ) ; 
		df.setMaximumFractionDigits ( 5 ) ; 
		df.setMinimumFractionDigits ( 5 ) ; 
		//System.out.println (df.format(d).replace(',', '.') );

		Double dd = Double.parseDouble( df.format(d).replace(',', '.') );
		//System.out.println ( dd.toString());

		ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
		DataOutputStream datastream = new DataOutputStream(bytestream);
		datastream.writeDouble(dd);
		datastream.flush();

		byte[] bytes = bytestream.toByteArray();

		for (int i=0; i<bytes.length; i++){
			b[i+1] = bytes[i];
		}

		nbOctet+=9;
		nbDonnee++;
		tab.add(new Flottant(d));
		return true;
	}

	// Ajout d'un numero aux donnees
	public boolean add(long i) throws Exception{
		@SuppressWarnings("unused")
		byte[] b;

		// nombre sur 1 octet
		if( i<= Byte.MAX_VALUE*2+1 && i >= Byte.MIN_VALUE){
			// 1 octet sign�
			if(i <= Byte.MAX_VALUE){
				b = new byte[] { (byte)0x01, (byte)i };
				nbOctet+=2;
				nbDonnee++;
				tab.add(new SignedByte(i));
				return true;
			}
			// 1 octet non sign�
			else if(i >= 0){
				b = new byte[] { (byte)0x11, (byte)i };
				nbOctet+=2;
				nbDonnee++;
				tab.add(new UnsignedByte(i));
				return true;
			}
		}

		// nombre sur 2 octets
		else if(i<= Short.MAX_VALUE*2+1 && i >= Short.MIN_VALUE){
			// 2 octets sign�s
			if (i <= Short.MAX_VALUE){
				b = new byte[] { (byte)0x02, (byte)((int)i>>>8), (byte)i };
				nbOctet+=3;
				nbDonnee++;
				tab.add(new SignedShort(i));
				return true;
			}
			// 2 octets non sign�s
			else if(i >= 0){
				b = new byte[] { (byte)0x12, (byte)((int)i>>>8), (byte)i };
				nbOctet+=3;
				nbDonnee++;
				tab.add(new UnsignedShort(i));
				return true;
			}
		}

		// nombre sur 4 octets
		else if(i <= Integer.MAX_VALUE*2+1 && i >= Integer.MIN_VALUE){
			// 4 octets sign�s
			if (i <= Integer.MAX_VALUE){
				b = new byte[] { (byte)0x04, (byte)((int)i>>>24), (byte)((int)i>>>16), (byte)((int)i>>>8), (byte)i };
				nbOctet+=5;
				nbDonnee++;
				tab.add(new SignedInt(i));
				return true;
			}
			// 4 octets non sign�s
			else if(i >= 0){
				b = new byte[] { (byte)0x14, (byte)((int)i>>>24), (byte)((int)i>>>16), (byte)((int)i>>>8), (byte)i };
				nbOctet+=5;
				nbDonnee++;
				tab.add(new UnsignedInt(i));
				return true;
			}
		}
		throw new Exception();
	}

	// Transformation de la trame en tableau d'octets
	public byte[] getTrameToBytes(){
		int indice = 3;
		byte[] tmp;
		byte[] t = new byte[nbOctet];
		t[0]= (byte)0xFF;
		t[1]= this.priorite;
		t[2]= (byte)this.nbDonnee;


		for(IDonnee donnee : tab){
			tmp = donnee.getTab();
			for(int j=0; j<tmp.length; j++)
				t[indice++] = tmp[j];
		}
		return t;
	}
}

}*/
